<div class="tpl-portlet-components">
	<div class="tpl-block">

		<div class="am-g">
			<div class="tpl-form-body tpl-form-line">
				<form class="am-form tpl-form-line-form" id="aform">
					<div class="am-form-group">
						<label for="user-name" class="am-u-sm-2 am-form-label">标题 </label>
						<div class="am-u-sm-10">
							<input name="title" type="text" class="tpl-form-input" id="user-name" placeholder="请输入标题文字">
							<!--<small>请填写标题文字10-20字左右。</small>-->
						</div>
					</div>
					
					<div class="am-form-group">
						<label for="user-weibo" class="am-u-sm-2 am-form-label">封面图</label>
						<div class="am-u-sm-10">
							<div class="am-form-group am-form-file">
								<div class="tpl-form-file-img">
									<img id="imgpreview" src="assets/img/a5.png" width="110" height="110" alt="">
									<input type="hidden" name="img" id="img" />
								</div>
								<button type="button" class="am-btn am-btn-danger am-btn-sm">
    								<i class="am-icon-cloud-upload"></i> 添加封面图片</button>
								<input id="doc-form-file" type="file" multiple>
							</div>
						</div>
					</div>

					<div class="am-form-group">
						<label for="user-weibo" class="am-u-sm-2 am-form-label">类型 </label>
						<div class="am-u-sm-10">
							<select id="types" name="typeid"></select>
							<div>
							</div>
						</div>
					</div>
					
					<div class="am-form-group">
						<label for="user-abstrct" class="am-u-sm-2 am-form-label">摘要</label>
						<div class="am-u-sm-10">
							<input name="abstrct" type="text" class="tpl-form-input" id="user-abstrct" placeholder="请输入摘要">
						</div>
					</div>

					<div class="am-form-group">
						<label for="user-intro" class="am-u-sm-2 am-form-label">隐藏文章</label>
						<div class="am-u-sm-10">
							<div class="tpl-switch">
								<input type="checkbox" class="ios-switch bigswitch tpl-switch-btn" checked />
								<div class="tpl-switch-btn-view">
									<div>
									</div>
								</div>
							</div>
						</div>
					</div>
					
					<div class="am-form-group">
						<label for="user-intro" class="am-u-sm-2 am-form-label">文章内容</label>
						<div class="am-u-sm-10">
							<div id="div1"></div>
							<textarea name="content" rows="10" id="blog-content" placeholder="请输入文章内容" style="display: none;"></textarea>
						</div>
					</div>

					<div class="am-form-group">
						<div class="am-u-sm-9 am-u-sm-push-3">
							<button type="button" class="am-btn am-btn-primary tpl-btn-bg-color-success " id="submit">提交</button>
						</div>
					</div>
				</form>

			</div>
		</div>
	</div>

</div>
<script type="text/javascript">
	    var E = window.wangEditor
        var editor = new E('#div1')
        var $text1 = $('#blog-content')
        editor.customConfig.onchange = function (html) {
            // 监控变化，同步更新到 textarea
            $text1.val(html)
        }
        editor.create()
        // 初始化 textarea 的值
        $text1.val(editor.txt.html());
        
        //上传图片
        $("#doc-form-file").change(function () {
        	console.log(this)
        	var file=this.files[0];
        	var reader=new FileReader();
        	reader.readAsDataURL(file);
        	reader.onload=function () {
        		$("#imgpreview").attr("src",this.result);
        		$("#img").val(this.result)
        	}
        });
        //请求文章类型
        $.get("allTypes",function (data) {
        	//console.log(data)
        	$.each(data, function(i,tn) {
        		$("#types").append("<option value='"+tn.id+"'>"+tn.name+"</option>")
        	});
        });      
        //提交数据
        $("#submit").click(function () {
        	$.post("articleSave",$("#aform").serialize(),function (data) {
        		alert(data);
        	})
        })
        
</script>